import datetime
import time


def get_date_noon(datetime_obj: datetime.datetime):
    """
    返回某个日期的中午12点
    """
    return datetime.datetime(datetime_obj.year, datetime_obj.month, datetime_obj.day, 12, 0, 0, 0)


def str_to_datetime(datetime_str: str):
    """
    字符串转datetime
    """
    return datetime.datetime.strptime(datetime_str, "%Y-%m-%d")


class DateTimeTool:
    time_obj = datetime.datetime.now()

    def __init__(self, date_str: str = None, datetime_str: str = None, datetime_obj: datetime.datetime = None,
                 dateTtime_str: str = None):
        if date_str is not None:
            self.time_obj = datetime.datetime.strptime(date_str, "%Y-%m-%d")
        if datetime_str is not None:
            self.time_obj = datetime.datetime.strptime(datetime_str, "%Y-%m-%d %H:%M:%S")
        if datetime_obj is not None:
            self.time_obj = datetime_obj
        if dateTtime_str is not None:
            if "Z" in dateTtime_str:
                dateTtime_str = dateTtime_str.split("Z")[0]
            self.time_obj = datetime.datetime.strptime(dateTtime_str, "%Y-%m-%dT%H:%M:%S")

    def get_noon(self):
        """
        获取datetime对象 当天时间12:00
        """
        return datetime.datetime(self.time_obj.year, self.time_obj.month, self.time_obj.day, 12, 0, 0, 0)

    def get_eighteen(self):
        """
        获取datetime对象 当天18:00
        """
        return datetime.datetime(self.time_obj.year, self.time_obj.month, self.time_obj.day, 18, 0, 0, 0)

    def get_datetime_obj(self):
        """
        获取datetime对象 当天00:00
        """
        return datetime.datetime(self.time_obj.year, self.time_obj.month, self.time_obj.day, 0, 0, 0, 0)

    def change_time(self, **kwargs):
        """
        修改时间
        """
        hour = kwargs.get("hour")
        minutes = kwargs.get("minutes")
        second = kwargs.get("second")
        return datetime.datetime(self.time_obj.year, self.time_obj.month, self.time_obj.day, hour, minutes, second, 0)

    def get_week_list(self, result_type=None):
        """
        获取 datetime对象 往后一周的日期
        """
        week_list = []
        for i in range(7):
            day_delta = datetime.timedelta(days=i)
            result_date = self.time_obj + day_delta

            if result_type is None:
                week_list.append(result_date.date())
            else:
                week_date = result_date.strftime("%Y-%m-%d")
                week_list.append(week_date)
        return week_list